package com.qr.backend.entity;

import lombok.Data;

/**
 * @author : jinxiaobo
 * @date : 2023年12月18日 17:45:55
 * @description : 基础返回结果封装
 */
@Data
public class RestInfo<T> {

    private Integer state;

    private String message;

    private Boolean success;

    private T data;

    private RestInfo(int status, Boolean success, String message) {
        this.state = status;
        this.success = success;
        this.message = message;
    }

    private RestInfo(int status, Boolean success, String message, T data) {
        this.state = status;
        this.success = success;
        this.message = message;
        this.data = data;
    }

    public static <T> RestInfo<T> success() {
        return new RestInfo<>(200, true, null);
    }

    public static <T> RestInfo<T> success(T data) {
        return new RestInfo<>(200, true, null, data);
    }

    public static <T> RestInfo<T> success(String message) {
        return new RestInfo<>(200, true, message);
    }

    public static <T> RestInfo<T> failure(int state) {
        return new RestInfo<>(state, false, null);
    }

    public static <T> RestInfo<T> failure(int state,String message) {
        return new RestInfo<>(state, false, message);
    }

}
